$NG.AllReady(function (page, { useAction, useBeforeClick, useValuesChange, useClick, useUpdateRow, subscribe, useUpdateRows }) {
    const mstform = $NG.getCmpApi("p_form_tcxy_m")
    const dgrid1 = $NG.getCmpApi("p_form_tcxy_m.")
    const getHeadValue = (str)=>mstform.getItem(str).getValue()


    if(page.oType == 'add'){
        getCntCbInfoByPhid()
    }

    useValuesChange(()=>{
        getCntCbInfoByPhid()
    },"p_form_tcxy_m.u_fbhtbh")    

    // 获取分包合同信息
    function getCntCbInfoByPhid() {
        const phid = getHeadValue("u_fbhtbh")
        if (!phid) {
            return
        }
        $NG.execServer("getCntCbInfoByPhid", { phid }, (res) => {
            if (res.count == 0) return
            const datas = JSON.parse(res.data)[0].extendObjects
            const arr = [
                {
                    key:"u_fbhtmc",
                    value:datas.cnt_name
                },
                {
                    key:"u_fbhtqdrq",
                    value:datas.user_htnqdsj
                },
                {
                    key: "u_fbhtbh",
                    value: datas.cnt_no
                },
                {
                    key: "u_fbhtje",
                    value: datas.user_htje
                },
                {
                    key: "u_fbsmc",
                    value: {
                        value: datas.fbsdw_phid,
                        label: datas.fbsdw_name
                    }
                },
                {
                    key: "u_sjkgsj",
                    value: datas.user_htjhkssj
                },
                {
                    key: "u_sjwgsj",
                    value: datas.user_htjhjssj
                }
            ]
            getSupplyInfo(datas.fbsdw_phid)
            setHeadValue(arr)
        })
    }

    // 获取分包商单位
    function getSupplyInfo(phid) {
        if (!phid) return
        $NG.execServer("getSupplyInfo", { phid }, (res) => {
            if (res.count == 0) return
            const datas = JSON.parse(res.data)[0].extendObjects
            const arr = [
                {
                    key: "u_fbsdz",
                    value: datas.taxaddress
                },
                {
                    key: "u_fbszrr",
                    value: datas.person
                },
                 {
                    key: "u_fbslxr",
                    value: datas.person
                },
                {
                    key:"u_fbf",
                    value:{
                        label:datas.fabs_name,
                        value:datas.fabs_phid
                    }
                },
                {
                    key: "u_lxdh",
                    value: datas.user_fddbrlxdh
                }
            ]
            setHeadValue(arr)
        })
    }


    // 赋值
    function setHeadValue(datas) {
        datas.forEach(item => {
            try {
                mstform.getItem(item.key).setValue(item.value)
            } catch (err) {
                console.log(`err`, err, item);
            }
        })
    }
})